﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;

namespace JobTillKm6_Test_WinForms
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void executeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            JobTillKm6.Features.JobTillKm6.JobTillKm6Process_App18 proc =
                new JobTillKm6.Features.JobTillKm6.JobTillKm6Process_App18();
            proc.Execute(Guid.NewGuid());
        }

        private void setEventReceiverToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string asmName_v1_0_0_0 = "JobTillKm6EventReceiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d5033a59bf4b079d";
            string asmName_v1_0_0_1 = "JobTillKm6EventReceiver, Version=1.0.0.1, Culture=neutral, PublicKeyToken=d5033a59bf4b079d";
            string className = "JobTillKm6EventReceiver.EventReceiver1.JobTillKm6EventReceiverHandler";
            SPList list = null;

            using (SPSite site = new SPSite(@"http://localhost/shops/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        // list = web.Lists["Кассовые документы"];
                    }
                    catch
                    {
                        ;
                    }

                    if (list != null)
                    {
                        try
                        {
                            for (int i = list.EventReceivers.Count; i > 0; i--)
                            {
                                if (list.EventReceivers[i - 1].Assembly == asmName_v1_0_0_0
                                    && list.EventReceivers[i-1].Class == className
                                    )
                                {
                                    list.EventReceivers[i-1].Delete();
                                }
                                else if (list.EventReceivers[i - 1].Assembly == asmName_v1_0_0_1
                                    && list.EventReceivers[i - 1].Class == className
                                    )
                                {
                                    list.EventReceivers[i - 1].Delete();
                                }
                            }
                        }
                        catch(Exception err)
                        {
                            ;
                        }

                        try
                        {
                            //list.EventReceivers.Add(
                            //    SPEventReceiverType.ItemAdded, asmName_v1_0_0_0, className);
                        }
                        catch(Exception err)
                        {
                            ;
                        }
                    }
                }
            }
        }

        private void makeMK6ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //JobTillKm6.Features.JobTillKm6.GeneratedClass o =
            //    new JobTillKm6.Features.JobTillKm6.GeneratedClass();
            //o.myData.OrgAddr_Line1 = "Line 1";
            //o.myData.OrgAddr_Line2 = "Line 2";
            //o.CreatePackage(@"c:\Tmp\Output.xlsx");
        }

        private void testToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Exception ret = null;
            DateTime retDT = new DateTime();
            Ko2.Portal.Env env = new Ko2.Portal.Env();
            //string str_1 = "OrgAddr_Line1";
            //string str_2 = "OrgAddr_Line2";
            //string str_OrgDeparment = "OKPO";
            //string str_INN = "INN";
            //string str_OKDP = "OKDP";
            //ret = env.SetWebSetting_DocAttr_OrgAddr_Line1(str_1);
            //ret = env.GetWebSetting_DocAttr_OrgAddr_Line1(ref str_1);
            //ret = env.SetWebSetting_DocAttr_OrgAddr_Line2(str_2);
            //ret = env.GetWebSetting_DocAttr_OrgAddr_Line2(ref str_2);
            //ret = env.SetWebSetting_DocAttr_OKPO(str_OrgDeparment);
            //ret = env.GetWebSetting_DocAttr_OKPO(ref str_OrgDeparment);
            //ret = env.SetWebSetting_DocAttr_INN(str_INN);
            //ret = env.GetWebSetting_DocAttr_INN(ref str_INN);
            //ret = env.SetWebSetting_DocAttr_OKDP(str_OKDP);
            //ret = env.GetWebSetting_DocAttr_OKDP(ref str_OKDP);
            ret = env.GetWebSetting_PossDocs_KM6_LastSuccessfully(ref retDT);
        }

    }
}
